// pages/login/index.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tanchang:false,
    xieyi:0,
    bianshe:true,

  },
  onLoad(){
    //console.log(wx.getStorageSync('openid'));
    if(wx.getStorageSync('openid')!=""){
      wx.switchTab({
        url: '/pages/article/index/index',
      })
    }
  },
clik:function(){
  //console.log("sb");
  this.setData({
    tanchang:!this.data.tanchang
  })
},
bianshe:function(){
  this.setData({
    bianshe:!this.data.bianshe
  })
  console.log(this.data.bianshe);
},
denglu(e){

wx.getUserProfile({
  desc: '展示用户信息',
  success:(res)=>{
    console.log(res);
 var nickName=res.userInfo.nickName;
 var gender;
    if(res.userInfo.gender==0){
      gender="男"
    }
    if(res.userInfo.gender==1){
      gender="女"
    }
    var imgUrl=res.userInfo.avatarUrl;
    wx.login({
      success: (res) => {
        var code=res.code;
        console.log(res.code);
        wx.request({
          url: 'http://127.0.0.1:9000/user1/login',
          method:'POST',
          data:{
            code:code,
            nickName:nickName,
            imgUrl:imgUrl,
            gender:gender
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded' 
            // 默认值
          },
          success: (res)=>{
            console.log(res.data)
          if(res.data==""){
            wx.showToast({
              title: '获取失败请重新获取',
            })
          }else{
            wx.setStorageSync('openid',res.data)
          wx.switchTab({
          url: '/pages/article/index/index',
        })

          }
        
         
          }
  
        })
       
  
      },
    })
  }
})
  
 

},
// checkopenid:function(){
//   wx.getStorageSync('openid')
//   console.log(wx.getStorageSync('openid'));
//   if(wx.getStorageSync('openid')!=""){
   
//         wx.switchTab({
//           url: '/pages/article/index/index',
//         })
//       }else{
// wx.showToast({
//   title: '获取的微信信息错误',
//   duration:2000
// })
//       }
  
// },


xieyi:function(e){
  console.log(e.detail.value);
  if(e.detail.value){
    this.setData({
      xieyi:e.detail.value
    })
  }

}
 
})